# -*- coding: utf-8 -*-
#
# File: CalShared.py
#
# Copyright (c) 2008 by []
# Generator: ArchGenXML Version 2.0
#            http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#

__author__ = """unknown <unknown>"""
__docformat__ = 'plaintext'

from AccessControl import ClassSecurityInfo
from Products.Archetypes.atapi import *
from zope.interface import implements
import interfaces

from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin

from Products.NetsightCal.config import *

##code-section module-header #fill in your manual code here
##/code-section module-header

schema = Schema((

    DateTimeField(
        name='startdatetime',
        widget=DateTimeField._properties['widget'](
            label="Start",
            label_msgid='NetsightCal_label_startdatetime',
            i18n_domain='NetsightCal',
        ),
        required=1,
    ),
    DateTimeField(
        name='enddatetime',
        widget=DateTimeField._properties['widget'](
            label="End",
            label_msgid='NetsightCal_label_enddatetime',
            i18n_domain='NetsightCal',
        ),
        required=1,
        validators=('isStartBeforeEnd',),
    ),
    TextField(
        name='comments',
        widget=TextAreaWidget(
            label="Comments",
            label_msgid='NetsightCal_label_comments',
            i18n_domain='NetsightCal',
        ),
    ),
),
)

##code-section after-local-schema #fill in your manual code here
##/code-section after-local-schema

CalShared_schema = BaseSchema.copy() + \
    schema.copy()

##code-section after-schema #fill in your manual code here
##/code-section after-schema

class CalShared(BaseContent, BrowserDefaultMixin):
    """
    """
    security = ClassSecurityInfo()
    implements(interfaces.ICalShared)

    meta_type = 'CalShared'
    _at_rename_after_creation = True

    schema = CalShared_schema

    ##code-section class-header #fill in your manual code here
    ##/code-section class-header

    # Methods

    # Manually created methods

    def start(self):
        """Define they start as start date attribute"""
        return self.getStartdatetime()

    def end(self):
        """Define the end as end date attribute"""
        return self.getEnddatetime()

    def sameday(self):
        """Returns true or false if the whole event happens on one day"""
        if self.start().strftime('%j%y') == self.end().strftime('%j%y'):
            return 1
        else:
            return 0

    def overDuration(self):
        """Define duration of overtime"""
        if self.end():
            dur = 24*(self.end() - self.start())
            hours = int(dur)
            minutes = int(60*(dur-hours)+0.5)
            if minutes == 60:
                minutes = 0;
                hours += 1;
            return { 'hours' : hours,
                     'minutes' : minutes,}
        return ''


registerType(CalShared, PROJECTNAME)
# end of class CalShared

##code-section module-footer #fill in your manual code here
##/code-section module-footer



